//
//  WDJMainController.m
//  wdj
//
//  Created by 蓝鳍互娱 on 2024/7/8.
//

#import "WDJMainController.h"
#import "WDJMainUserView.h"
#import "WDJMainAgreementView.h"
#import "WDJVipController.h"
@interface WDJMainController ()
@property (nonatomic,strong) WDJMainUserView *mainUserView;

@end

@implementation WDJMainController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = true;
    [self wdjCreatView];
}
- (void)wdjCreatView{
    UIImageView * mainBgImgView = [[UIImageView alloc] init];
    mainBgImgView.image = [WDjWholeData wholeImageNamed:@"wdj_WorldDayBg"];
    mainBgImgView.userInteractionEnabled = true;
    [self.view addSubview:mainBgImgView];
    [mainBgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(0));
    }];
    UIButton * mainNavBackBtn = [[UIButton alloc] init];
    [mainNavBackBtn setBackgroundImage:[WDjWholeData wholeImageNamed:@"wdj_NavBack"] forState:UIControlStateNormal];
    [mainNavBackBtn addTarget:self action:@selector(mainNavBack) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:mainNavBackBtn];
    [mainNavBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:24]));
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:64]));
        make.width.equalTo(@([WDjWholeData wholeScreewRatio:64]));
        make.top.equalTo(@([WDjWholeData wholeScreewRatio:12]+[WDjWholeData wholeTopSafeH]));
    }];
    UILabel * mainNavTitleLab = [[UILabel alloc] init];
    mainNavTitleLab.font = [UIFont systemFontOfSize:[WDjWholeData wholeScreewRatio:34] weight:UIFontWeightRegular];
    mainNavTitleLab.textColor = [WDjWholeData wholeColorHexString:@"#FFFFFF"];
    mainNavTitleLab.text = @"我的";
    [self.view addSubview:mainNavTitleLab];
    [mainNavTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(mainNavBackBtn);
        make.centerX.equalTo(self.view);
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:50]));
    }];
    self.mainUserView = [[WDJMainUserView alloc] init];
    self.mainUserView.hidden = true;
    [self.view addSubview:self.mainUserView];
    [self.mainUserView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:24]));
        make.right.equalTo(@(-[WDjWholeData wholeScreewRatio:24]));
        make.top.equalTo(@([WDjWholeData wholeScreewRatio:133]+[WDjWholeData wholeTopSafeH]));
//        make.height.equalTo(@([WDjWholeData wholeScreewRatio:220]));
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:0]));
    }];
    WeakSelf
    self.mainUserView.MainOpenVipBlock = ^{
        WDJVipController * wdjVipCtrl = [[WDJVipController alloc] init];
        UINavigationController * wdjVipNavCtrl = [[UINavigationController alloc] initWithRootViewController:wdjVipCtrl];
        wdjVipNavCtrl.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [weakSelf presentViewController:wdjVipNavCtrl animated:true completion:^{}];
        wdjVipCtrl.ApplePayScuessBlock = ^{
            [weakSelf.mainUserView wdjMainUpdataVip];
        };
    };
    WDJMainAgreementView * mainAgreementuserView = [[WDJMainAgreementView alloc] init];
    [self.view addSubview:mainAgreementuserView];
    [mainAgreementuserView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:0]));
        make.right.equalTo(@(-[WDjWholeData wholeScreewRatio:0]));
        make.top.equalTo(self.mainUserView.mas_bottom).offset([WDjWholeData wholeScreewRatio:15]);
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:99]));
    }];
    mainAgreementuserView.mainAgreementType = MainAgreementTypeUser;
    mainAgreementuserView.MainAgreementBlock = ^(WDJMainAgreementType mainAgreementType) {
        if(mainAgreementType == MainAgreementTypeUser){
            WDJWebController * wdjWebCtrl = [[WDJWebController alloc] init];
            wdjWebCtrl.wdjWebUrl = [WDjWholeData wdjPublicForUserAgreement];
            wdjWebCtrl.isWhiteBack = false;
            [weakSelf.navigationController pushViewController:wdjWebCtrl animated:true];
        }
    };
    WDJMainAgreementView * mainAgreementpriviceView = [[WDJMainAgreementView alloc] init];
    [self.view addSubview:mainAgreementpriviceView];
    [mainAgreementpriviceView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([WDjWholeData wholeScreewRatio:0]));
        make.right.equalTo(@(-[WDjWholeData wholeScreewRatio:0]));
        make.top.equalTo(mainAgreementuserView.mas_bottom).offset([WDjWholeData wholeScreewRatio:4]);
        make.height.equalTo(@([WDjWholeData wholeScreewRatio:99]));
    }];
    mainAgreementpriviceView.mainAgreementType = MainAgreementTypePrivice;
    mainAgreementpriviceView.MainAgreementBlock = ^(WDJMainAgreementType mainAgreementType) {
        if(mainAgreementType == MainAgreementTypePrivice){
            WDJWebController * wdjWebCtrl = [[WDJWebController alloc] init];
            wdjWebCtrl.wdjWebUrl = [WDjWholeData wdjPublicForPriAgreement];
            wdjWebCtrl.isWhiteBack = false;
            [weakSelf.navigationController pushViewController:wdjWebCtrl animated:true];
        }
    };
    [self.mainUserView wdjMainUpdataVip];
}
- (void)mainNavBack{
    [self.navigationController popViewControllerAnimated:true];
}
@end
